\begin{verbatim}
function TranslationCorrelations(S1,S2)
    // The sequence of correlations of the sequence S1 with the 
    // cyclic translations of the sequence S2.

    n := #S1;
    error if n ne #S2, "Arguments must be of the same length."; 

    // Compute the mean value of each sequence: 
    mu1 := &+[ S1[k] : k in [1..n] ]/n;
    mu2 := &+[ S2[k] : k in [1..n] ]/n;

    // Compute the standard deviations of each sequence:
    sig1 := Sqrt(&+[ (S1[k]-mu1)^2 : k in [1..n] ]);
    sig2 := Sqrt(&+[ (S2[k]-mu2)^2 : k in [1..n] ]);

    sig := sig1*sig2;
    CorrSeq := [ ];
    for j in [1..n] do
        Corr := &+[ (S1[i] - mu1) * (S2[ij] - mu2) / sig
            where ij := ((i+j-1) mod n) + 1 : i in [1..n] ];
        Append(~CorrSeq,<j,Corr>);
    end for;
    return CorrSeq;
end function;
\end{verbatim}
